package com.longcai.controller.homepage;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.longcai.bean.ApiResult;
import com.longcai.entity.homepage.ClyjNearbyBanner;
import com.longcai.service.homepage.ClyjNearbyBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 附近-banner 前端控制器
 * </p>
 *
 * @author LWK
 * @since 2019-03-20
 */
@Controller
@RequestMapping("/clyjNearbyBanner")
public class ClyjNearbyBannerController {

    @Autowired
    ClyjNearbyBannerService bannerService;

    /**
     * description: 首页banner展示
     * author: LWK
     * time： 09点09分
     */
    @RequestMapping("/getHomepageBannerList")
    @ResponseBody
    public ApiResult<List<ClyjNearbyBanner>> getHomepageBannerList(@RequestBody JSONObject params) {
        ApiResult<List<ClyjNearbyBanner>> result = new ApiResult<List<ClyjNearbyBanner>>();
        try {
            QueryWrapper<ClyjNearbyBanner> queryWrapper = new QueryWrapper<ClyjNearbyBanner>();
            //banner类型 0：首页banner；1：附近页banner
            String banner_type = params.getString("banner_type");
            queryWrapper.eq("status", 0);
            queryWrapper.eq("banner_type", banner_type);
            queryWrapper.orderByAsc("banner_sort");
            result.success();
            result.setData(bannerService.selectList(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode("-1");
            result.fail("查询失败：" + e.getMessage());
        }
        return result;
    }
}

